# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=libmimic
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.0.4
pkgrel=3
pkgdesc="An open source video encoding/decoding library for Mimic V2.x (mingw-w64)"
arch=('any')
url="https://farsight.sourceforge.io/"
license=("LGPL")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc" "${MINGW_PACKAGE_PREFIX}-doxygen")
depends=("${MINGW_PACKAGE_PREFIX}-glib2")
options=('strip' 'staticlibs')
source=("https://downloads.sourceforge.net/sourceforge/farsight/${_realname}-${pkgver}.tar.gz"
        0001-update-ac-and-silent-rules.mingw.patch
        0002-no-undefined.mingw.patch
        0003-link-to-glib.mingw.patch)
sha256sums=('bd7b9bd52ee7bf25df46f6d3d0ed896d212fc3d96907ac1b01d3d126a48bbb34'
            '0b20a7602e38aa4f1b39ff53125df5348a2e914a0f5158983c5d905186769836'
            'dbac64cfd6ab498f27ee7ab83e129c580a136e125b3e4ab74b2148753b94e4c0'
            '230d2bfb5a5f380262aae11ae4436589d17a49f5936d1d7283f547d141c86fea')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  patch -p1 -i "${srcdir}"/0001-update-ac-and-silent-rules.mingw.patch
  patch -p1 -i "${srcdir}"/0002-no-undefined.mingw.patch
  patch -p1 -i "${srcdir}"/0003-link-to-glib.mingw.patch

  WANT_AUTOMAKE=latest autoreconf -fi
}

build() {
  [[ -d "${srcdir}/build-${MINGW_CHOST}" ]] && rm -rf "${srcdir}/build-${MINGW_CHOST}"
  mkdir -p "${srcdir}/build-${MINGW_CHOST}"
  cd "${srcdir}/build-${MINGW_CHOST}"
  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --enable-shared \
    --enable-static

  cd doc
  ${MINGW_PREFIX}/bin/doxygen -u
  cd ..

  make
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR="${pkgdir}" install
}
